import type { Component } from "vue";
import type { FormType } from "./type";
import {
  ElInput,
  ElInputNumber,
  ElAutocomplete,
  ElSelect,
  ElCascader,
  ElSelectV2,
  ElTimePicker,
  ElTimeSelect,
  ElDatePicker,
  ElRadio,
  ElCheckbox,
  ElCheckboxGroup,
  ElColorPicker,
  ElRate,
  ElSlider,
  ElSwitch,
  ElCheckboxButton,
  ElRadioButton,
  ElRadioGroup,
  ElUpload,
} from 'element-plus'

/**
 * 将FormType转成Component
 * @param type FormType
 */
export const tranElComponent = (type: FormType) => {
  if (type === 'input') return ElInput as Component // 输入框
  if (type === 'inputNumber') return ElInputNumber as Component // 数字输入框
  if (type === 'autocomplete') return ElAutocomplete as Component // 自动补全输入框
  if (type === 'select') return ElSelect as Component // 选择器
  if (type === 'cascader') return ElCascader as Component // 级联选择器
  // if (type === 'selectV2') return ElSelectV2 as Component // 虚拟化选择器
  if (type === 'datePicker') return ElDatePicker as Component // 日期时间选择器
  if (type === 'timePicker') return ElTimePicker as Component // 时间选择器
  if (type === 'timeSelect') return ElTimeSelect as Component // 时间选择
  if (type === 'radio') return ElRadio as Component // 单选框
  if (type === 'radioButton') return ElRadioButton as Component // 按钮样式单选框
  if (type === 'radioGroup') return ElRadioGroup as Component // 单选框组
  if (type === 'checkbox') return ElCheckbox as Component // 多选框
  if (type === 'checkboxButton') return ElCheckboxButton as Component // 按钮样式多选框
  if (type === 'checkboxGroup') return ElCheckboxGroup as Component // 多选框组
  if (type === 'colorPicker') return ElColorPicker as Component // 取色器
  if (type === 'rate') return ElRate as Component // 评分
  if (type === 'slider') return ElSlider as Component // 滑块
  if (type === 'switch') return ElSwitch as Component // 开关
  if (type === 'upload') return ElUpload as Component // 上传
  // if (type === 'custom') return props.item.is as Component // 自定义
  if (type === 'view') return 'div' // 仅展示
  console.error(`ConfigForm：组件类型错误，不存在type为${type}的元素`)
  return type
}